package com.xbb.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xbb.entity.Role;
import com.xbb.entity.User;
import com.xbb.entity.UserParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.validation.Valid;
import java.util.List;

public interface UserMapper extends BaseMapper<User>{

    //获取咨询师列表--多条件
    public List<User> getZiXunShiByWeight(UserParam user);

    //获取网络咨询师列表
    List<User> getWangLuoZiXunShiList(UserParam user);

    //修改咨询师权重
    public boolean updateZiXunShiWeight(User user);

    //获取签到列表信息
    public List<User> getQianDaoList(UserParam user);

    //批量修改user表分配状态
    public boolean updateBatchUser(@Param("ids") List<Integer> ids,@Param("i") Integer i);

    //修改用户密码
    @Update("update users set password=#{password} where login_name=#{loginName}")
    public Integer updatePassWord(User user);

    //修改密码错误次数
    @Update("update users set psd_wrong_time=psd_wrong_time+1 where login_name=#{loginName}")
    Integer updateWrongNum(String loginName);

    //查询密码错误次数
    @Select("select psd_wrong_time from users where login_name=#{loginName}")
    Integer getWrongNum(String loginName);

    //用户锁定--登录验证
    @Update("update users set is_lockout='是',lock_time=now() where login_name=#{loginName}")
    Integer updateLock(String loginName);

    //用户解锁--登录验证
    @Update("update users set is_lockout='否',last_login_time=now() where login_name=#{loginName}")
    Integer updateLockOut(String loginName);

    //清除密码错误次数
    @Update("update users set psd_wrong_time=0 where login_name=#{loginName}")
    Integer updateEmptyWrongNum(String loginName);

    //查询用户锁定的状态
    @Select("select is_lockout from users where login_name=#{loginName}")
    String getLock(String loginName);

    //验证登录者角色是不是管理员--方便锁定设置初始密码
    @Select("select * from roles where id in(\n" +
            "select role_id from userroles where user_id in(\n" +
            "select id from users where login_name=#{loginName}))")
    List<Role> yanzhengGuanLiYuan(String loginName);


    //查询用户名--验证用户名不重复
    @Select("select login_name from users where login_name=#{loginName}")
    List<User> getUserNameByLoginName(@Valid User user);

    //查询用户是否拥有角色--验证删除用户信息
    @Select("select * from userroles where user_id=#{id}")
    List<User> getUserContainsRole(Integer id);


}
